//实现ls -l的功能，即列出当前目录下所有文件和文件夹

#include"ls.h"


int main(int argc, char *argv[])
{
    const size_t DIR_PATH_SIZE=PATH_MAX*sizeof(char);
    //char dirPath[PATH_MAX];
    char*dirPath=malloc(DIR_PATH_SIZE);
    pthread_t tid;
    if(argc == 1)
    {
    	// 获取当前路径信息
    	if (getcwd(dirPath, PATH_MAX) == NULL){
        	printf("getcwd error\n");
            return 1;
    	}
    }
    else if(argc == 2)
    {
		memset(dirPath, '\0', DIR_PATH_SIZE);
    	strcpy(dirPath,argv[1]);
    }
    else if(argc > 2)
    {
    	printf("usage: myls or myls [directory]\n");
        return 2;
    }
    rel_start=strlen(dirPath);
    pthread_mutex_init(&stdio_mtx,NULL);
    pthread_mutex_init(&mtx,NULL);
    waiting_cnt_add();
//    ls(dirPath);
    pthread_create(&tid,NULL,(void *)ls,dirPath);
    //pthread_join(tid,NULL);
    pthread_detach(tid);
    while(waiting_cnt!=0)sched_yield();
    pthread_mutex_destroy(&mtx);
    pthread_mutex_destroy(&stdio_mtx);
    return 0;
}
